package com.yanwq.sayhi.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 * 作者：yanweiqiang。
 * 日期：2016/1/29。
 */
@RestController
@ControllerAdvice
public class ExHandler {

    @ExceptionHandler(ExResponse.class)
    @ResponseStatus(code = HttpStatus.BAD_REQUEST)
    public ExMsg handleBadRequestException(ExResponse e) {
        return new ExMsg(e.getCode(), e.getMsg());
    }

    /*@ExceptionHandler(SQLException.class)
    @ResponseStatus(code = HttpStatus.BAD_REQUEST)
    public ExMsg handleSQLException(SQLException e) {
        return new ExMsg(100, e.getMessage());
    }

    @ExceptionHandler(IOException.class)
    @ResponseStatus(code = HttpStatus.BAD_REQUEST)
    public ExMsg handleIOException(IOException e) {
        return new ExMsg(100, e.getMessage());
    }

    @ExceptionHandler(NullPointerException.class)
    @ResponseStatus(code = HttpStatus.BAD_REQUEST)
    public ExMsg handleNullPointerException(NullPointerException e) {
        return new ExMsg(100, e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseStatus(code = HttpStatus.BAD_REQUEST)
    public ExMsg handleException(Exception e) {
        return new ExMsg(100, e.getMessage());
    }*/
}
